package dk.itu.amds.auctionhouse.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Random;

public class AuctionItem implements Serializable{
	private int id;
	private String name;
	private String description;
	private float startPrice;
	private float maxPrice;
	private int sellerUserId;
	private int sellerBrokerAccountId;
	private boolean auctionDone;
	private ArrayList<Bid> bids = new ArrayList<Bid>();
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}

	public boolean isAuctionDone(){
		return auctionDone;
	}
	public void setAuctionDone(boolean auctionDone){
		this.auctionDone = auctionDone;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public float getStartPrice() {
		return startPrice;
	}
	public void setStartPrice(float startPrice) {
		this.startPrice = startPrice;
	}
	public float getMaxPrice() {
		return maxPrice;
	}
	public void setMaxPrice(float maxPrice) {
		this.maxPrice = maxPrice;
	}
	public int getSellerUserId() {
		return sellerUserId;
	}
	public void setSellerUserId(int sellerUserId) {
		this.sellerUserId = sellerUserId;
	}
	public int getSellerBrokerAccountId() {
		return sellerBrokerAccountId;
	}
	public void setSellerBrokerAccountId(int sellerBrokerAccountId) {
		this.sellerBrokerAccountId = sellerBrokerAccountId;
	}
	public void addBid(Bid bid) {
		bids.add(bid);
	}
	public float getHighestBid(){
		if(!bids.isEmpty()) {
			return bids.get(bids.size() - 1).getBidPrice();
		} else {
			return startPrice;
		}
	}
	public ArrayList<Bid> getBids() {
		return bids;
	}
	public AuctionItem(String name, String description, float startPrice, float maxPrice,
			int sellerUserId, int sellerBrokerAccountId) {
		super();
		this.name = name;
		this.description = description;
		this.startPrice = startPrice;
		this.maxPrice = maxPrice;
		this.sellerUserId = sellerUserId;
		this.sellerBrokerAccountId = sellerBrokerAccountId;
		this.auctionDone = false;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("AuctionItem[");
		sb.append("Id: " + id + ", ");
		sb.append("SellerUserId: " + sellerUserId + ", ");
		sb.append("Name: " + name + ", ");
		sb.append("Description: " + description + ", ");
		sb.append("Start price: " + startPrice + ", ");
		sb.append("Max price: " + maxPrice + "]");
		sb.append("Seller broker account id: " + sellerBrokerAccountId + "]");
		sb.append("\nBids:");
		for(Bid bid : bids) {
			sb.append(bid + "\n");
		}
		
		
		return sb.toString();
	}
	
}
